import java.io.*;

//案例：复制单级文件夹
//需求：把 “MyFile\\src\\tmp\\JavaSE" 这个文件夹复制到 tmp 下，并重命名为 copy1
public class CopyDirectory {
    public static void main(String[] args) throws IOException {
        File source = new File("MyFile\\\\src\\\\tmp\\\\JavaSE");
        File destination = new File("MyFile\\src\\tmp\\copy1");
        if(!destination.exists())
                destination.mkdir();
        copyFile_(source,destination);
    }


    public static void copyFile_(File source,File destination) throws IOException {
        File[] listFiles = source.listFiles();
        for(File file : listFiles){
            String filename = file.getName();
            File fileCopy = new File(destination,filename);
            FileInputStream fis = new FileInputStream(file.getAbsoluteFile());
            FileOutputStream fos = new FileOutputStream(fileCopy);
            int len;
            byte[] bys = new byte[1024];
            while((len = fis.read(bys)) != -1){
                fos.write(bys,0,len);
                fos.flush();
            }
            fis.close();
            fos.close();
        }
    }


}
